home *** CD-ROM | disk | FTP | other *** search
/ Internet Publisher's Toolbox 2.0 / Internet Publisher's Toolbox.iso / internet / ntserver / wtsource / zutil.h < prev   
Encoding:
C/C++ Source or Header  |  1994-02-15  |  10.2 KB  |  301 lines

  1. /* WIDE AREA INFORMATION SERVER SOFTWARE:
  2.    No guarantees or restrictions.  See the readme file for the full standard
  3.    disclaimer.    
  4.   
  5.    3.26.90    Harry Morris, morris@think.com
  6.    3.30.90  Harry Morris - Changed any->bits to any->bytes
  7.    4.11.90  HWM - fixed include file names, changed 
  8.                      writeCompressedIntegerWithPadding() to
  9.                   writeCompressedIntWithPadding()
  10. */
  11.  
  12. /* Copyright (c) CNIDR (see ../COPYRIGHT) */
  13.  
  14.  
  15. #ifndef _H_utils_Z39_50
  16. #define _H_utils_Z39_50
  17.  
  18. #include "cdialect.h"
  19.  
  20. #include "cutil.h"
  21.  
  22. /*----------------------------------------------------------------------*/
  23. /* Data types / constants */
  24.  
  25. /* bytes to leave for the header size info */
  26. #define HEADER_LEN    (size_t)2 
  27.  
  28. typedef long pdu_type;
  29.  
  30. #define    initAPDU            (pdu_type)20
  31. #define    initResponseAPDU        (pdu_type)21
  32. #define    searchAPDU            (pdu_type)22
  33. #define    searchResponseAPDU        (pdu_type)23
  34. #define    presentAPDU            (pdu_type)24
  35. #define    presentResponseAPDU        (pdu_type)25
  36. #define    deteteAPDU            (pdu_type)26
  37. #define    deleteResponseAPDU        (pdu_type)27
  38. #define    accessControlAPDU        (pdu_type)28
  39. #define    accessControlResponseAPDU    (pdu_type)29
  40. #define    resourceControlAPDU        (pdu_type)30
  41. #define    resourceControlResponseAPDU    (pdu_type)31
  42.  
  43. typedef struct any {    /* an any is a non-ascii string of characters */
  44.     unsigned long    size; 
  45.     char*            bytes;
  46.     } any;
  47.     
  48. typedef any    bit_map;     /* a bit_map is a group of packed bits */
  49.  
  50. typedef unsigned long data_tag;
  51.  
  52. #define DT_PDUType            (data_tag)1     
  53. #define    DT_ReferenceID            (data_tag)2
  54. #define    DT_ProtocolVersion        (data_tag)3
  55. #define    DT_Options            (data_tag)4
  56. #define    DT_PreferredMessageSize        (data_tag)5
  57. #define    DT_MaximumRecordSize        (data_tag)6
  58. #define    DT_IDAuthentication        (data_tag)7
  59. #define    DT_ImplementationID        (data_tag)8
  60. #define    DT_ImplementationName        (data_tag)9
  61. #define    DT_ImplementationVersion    (data_tag)10
  62. #define    DT_UserInformationField        (data_tag)11
  63. #define    DT_Result            (data_tag)12
  64. #define    DT_SmallSetUpperBound        (data_tag)13
  65. #define    DT_LargeSetLowerBound        (data_tag)14
  66. #define    DT_MediumSetPresentNumber    (data_tag)15
  67. #define    DT_ReplaceIndicator        (data_tag)16
  68. #define    DT_ResultSetName        (data_tag)17
  69. #define    DT_DatabaseNames        (data_tag)18
  70. #define    DT_ElementSetNames         (data_tag)19
  71. #define    DT_QueryType            (data_tag)20
  72. #define    DT_Query            (data_tag)21
  73. #define    DT_SearchStatus            (data_tag)22
  74. #define    DT_ResultCount            (data_tag)23
  75. #define    DT_NumberOfRecordsReturned    (data_tag)24
  76. #define    DT_NextResultSetPosition    (data_tag)25
  77. #define    DT_ResultSetStatus        (data_tag)26
  78. #define    DT_PresentStatus        (data_tag)27
  79. #define    DT_DatabaseDiagnosticRecords    (data_tag)28
  80. #define    DT_NumberOfRecordsRequested    (data_tag)29
  81. #define    DT_ResultSetStartPosition    (data_tag)30
  82. #define    DT_ResultSetID            (data_tag)31
  83. #define    DT_DeleteOperation        (data_tag)32
  84. #define    DT_DeleteStatus            (data_tag)33
  85. #define    DT_NumberNotDeleted        (data_tag)34
  86. #define    DT_BulkStatuses            (data_tag)35
  87. #define    DT_DeleteMSG            (data_tag)36
  88. #define    DT_SecurityChallenge        (data_tag)37
  89. #define    DT_SecurityChallengeResponse    (data_tag)38
  90. #define    DT_SuspendedFlag        (data_tag)39
  91. #define    DT_ResourceReport        (data_tag)40
  92. #define    DT_PartialResultsAvailable    (data_tag)41
  93. #define    DT_ContinueFlag            (data_tag)42
  94. #define    DT_ResultSetWanted        (data_tag)43
  95.  
  96. #define UNUSED    -1
  97.  
  98. /* number of bytes required to represent the following sizes in compressed 
  99.    integer format
  100.  */
  101. #define CompressedInt1Byte    128         /* 2 ^ 7 */
  102. #define CompressedInt2Byte    16384         /* 2 ^ 14 */
  103. #define CompressedInt3Byte    2097152     /* 2 ^ 21 */
  104. /* others may follow ... */
  105.  
  106. /* types of query */
  107. #define QT_0    "0"    /* query whose non-standard format has been agreed upon
  108.                client and server */
  109. /* values for InitAPDU option element */
  110. #define    WILL_USE        TRUE
  111. #define WILL_NOT_USE        FALSE
  112. #define WILL_SUPPORT        TRUE
  113. #define WILL_NOT_SUPPORT    FALSE
  114.  
  115. /* values for InitResponseAPDU result element */
  116. #define ACCEPT    TRUE
  117. #define REJECT    FALSE
  118.  
  119. /* values for SearchAPDU replace indicator element */
  120. #define ON    TRUE
  121. #define OFF    FALSE
  122.  
  123. /* values for SearchResponseAPDU search status element */
  124. #define    SUCCESS    0 /* intuitive huh? */
  125. #define FAILURE    1
  126.  
  127. /* values for SearchResponseAPDU result set status element */
  128. #define    SUBSET    1
  129. #define INTERIM    2
  130. #define NONE    3
  131.  
  132. /* values for SearchResponseAPDU present status element */
  133. /* SUCCESS already defined */
  134. #define PARTIAL_1    1
  135. #define PARTIAL_2    2
  136. #define PARTIAL_3    3
  137. #define PARTIAL_4    4
  138. #define PS_NONE        5 /* can't use NONE since it was used by result 
  139.                  set status */
  140.  
  141. #ifndef BSD 
  142. #define DIAGNOSTIC_CODE_SIZE    (size_t)3
  143. #else  /* BSD only on a encore/gould */
  144. #define DIAGNOSTIC_CODE_SIZE    3
  145. #endif /* BSD */
  146.  
  147. typedef struct diagnosticRecord 
  148.  { boolean    SURROGATE;
  149.    char        DIAG[DIAGNOSTIC_CODE_SIZE];
  150.    char*     ADDINFO;
  151.  } diagnosticRecord;
  152.  
  153. #define D_PermanentSystemError           "S1"
  154. #define D_TemporarySystemError           "S2"
  155. #define D_UnsupportedSearch           "S3"
  156. #define D_TermsOnlyStopWords           "S5"
  157. #define D_TooManyArgumentWords           "S6"
  158. #define D_TooManyBooleanOperators      "S7"
  159. #define D_TooManyTruncatedWords           "S8"
  160. #define D_TooMany IncompleteSubfields  "S9"
  161. #define D_TruncatedWordsTooShort       "SA"
  162. #define D_InvalidFormatForRecordNumber "SB"
  163. #define D_TooManyCharactersInSearch    "SC"
  164. #define D_TooManyRecordsRetrieved      "SD"
  165. #define D_PresentRequestOutOfRange     "SF"
  166. #define D_SystemErrorInPresentRecords  "SG"
  167. #define D_RecordNotAuthorizedToBeSent  "SH"
  168. #define D_RecordExceedsPrefMessageSize "SI"
  169. #define D_RecordExceedsMaxRecordSize   "SJ"
  170. #define D_ResultSetNotSuppAsSearchTerm "SK"
  171. #define D_OnlyOneRsltSetAsSrchTermSupp "SL"
  172. #define D_OnlyANDingOfASnglRsltSetSupp "SM"
  173. #define D_RsltSetExistsNoReplace       "SN"
  174. #define D_ResultSetNamingNotSupported  "SO"
  175. #define D_CombinationDatabasesNotSupp  "SP"
  176. #define D_ElementSetNamesNotSupported  "SQ"
  177. #define D_ElementSetNameNotValid       "SR"
  178. #define D_OnlyASingleElmntSetNameSupp  "SS"
  179. #define D_ResultSetDeletedByTarget     "ST"
  180. #define D_ResultSetIsInUse             "SU"
  181. #define D_DatabasesIsLocked            "SV"
  182. #define D_TerminatedByNoContinueResp   "SW"
  183. #define D_ResultSetDoesNotExist        "SX"
  184. #define D_ResExNoResultsAvailable      "SY"
  185. #define D_ResExUnpredictableResults    "SZ"
  186. #define D_ResExValidSubsetOfResults    "T1"
  187. #define D_AccessControlFailure         "T2"
  188. #define D_SecurityNotIssuedReqTerm     "T3"
  189. #define D_SecurityNotBeIssuedRecNotInc "T4"
  190.  
  191. /*----------------------------------------------------------------------*/
  192.  
  193. /* for internal error handling */
  194.  
  195. #ifndef _C_utils_Z39_50_
  196. extern char* readErrorPosition;     /* pos where buf stoped making sense */
  197. #endif /*ndef _C_utils_Z39_50_ */
  198.  
  199. /* the following are macros so that they can return OUT of the function
  200.    which calls them
  201.  */
  202.  
  203. #define RETURN_ON_NULL(var)                     \
  204.     if (var == NULL)                          \
  205.       return(NULL); /* jump out of caller */
  206.  
  207. #define REPORT_READ_ERROR(pos)                     \
  208.     { readErrorPosition = (pos);                \
  209.       return(NULL); /* jump out of caller */        \
  210.     }
  211.  
  212. #define CHECK_FOR_SPACE_LEFT(spaceNeeded,spaceLeft)        \
  213.     { if (*spaceLeft >= spaceNeeded)            \
  214.         (*spaceLeft) -= spaceNeeded;            \
  215.       else                            \
  216.        { *spaceLeft = 0;                     \
  217.          return(NULL); /* jump out of the caller */     \
  218.        }                            \
  219.     }
  220.  
  221. /*----------------------------------------------------------------------*/
  222.  
  223. #ifdef __cplusplus
  224. /* declare these as C style functions */
  225. extern "C"
  226.     {
  227. #endif /* def __cplusplus */
  228.  
  229. diagnosticRecord* makeDiag _AP((boolean surrogate,char* code,char* addInfo));
  230. void freeDiag _AP((diagnosticRecord* diag));
  231. char* writeDiag _AP((diagnosticRecord* diag,char* buffer,long* len));
  232. char* readDiag _AP((diagnosticRecord** diag,char* buffer));
  233.  
  234. char* writeCompressedInteger _AP((unsigned long num,char* buf,long* len));
  235. char* readCompressedInteger _AP((unsigned long *num,char* buf));
  236. char* writeCompressedIntWithPadding _AP((unsigned long num,unsigned long size,
  237.                      char* buffer,long* len));
  238. unsigned long writtenCompressedIntSize _AP((unsigned long num));
  239.  
  240. char* writeTag _AP((data_tag tag,char* buf,long* len));
  241. char* readTag _AP((data_tag* tag,char* buf));
  242. data_tag peekTag _AP((char* buf));
  243. unsigned long writtenTagSize _AP((data_tag tag));
  244.  
  245. any* makeAny _AP((unsigned long size,char* data));
  246. void freeAny _AP((any* a));
  247. any* duplicateAny _AP((any* a));
  248. char* writeAny _AP((any* a,data_tag tag,char* buffer,long* len));
  249. char* readAny _AP((any** anAny,char* buffer));
  250. unsigned long writtenAnySize _AP((data_tag tag,any* a));
  251.  
  252. any* stringToAny _AP((char* s));
  253. char* anyToString _AP((any* a));
  254. unsigned long writtenStringSize _AP((data_tag tag,char* s));
  255.  
  256. any* longToAny _AP((long Num));
  257. long anyToLong _AP((any* a));
  258.  
  259. char* writeString _AP((char* s,data_tag tag,char* buffer,long* len));
  260. char* readString _AP((char** s,char* buffer));
  261.  
  262. bit_map* makeBitMap _AP((unsigned long numBits,...));
  263. void freeBitMap _AP((bit_map* bm));
  264. boolean bitAtPos _AP((long pos,bit_map* bm));
  265. char* writeBitMap _AP((bit_map* bm,data_tag tag,char* buffer,long* len));
  266. char* readBitMap _AP((bit_map** bm,char* buffer));
  267.  
  268. char* writeByte _AP((unsigned long byte,char* buf,long* len));
  269. char* readByte _AP((unsigned char* byte,char* buf));
  270.  
  271. char* writeBoolean _AP((boolean flag,char* buf,long* len));
  272. char* readBoolean _AP((boolean* flag,char* buf));
  273.  
  274. char* writePDUType _AP((pdu_type pduType,char* buf,long* len));
  275. char* readPDUType _AP((pdu_type* pduType,char* buf));
  276. pdu_type peekPDUType _AP((char* buf));
  277.  
  278. char* writeBinaryInteger _AP((long num,unsigned long size,
  279.                   char* buf,long* len));
  280. char* readBinaryInteger _AP((long* num,unsigned long size,char* buf));
  281. unsigned long writtenCompressedBinIntSize _AP((long num));
  282.  
  283. char* writeNum _AP((long num,data_tag tag,char* buffer,long* len));
  284. char* readNum _AP((long* num,char* buffer));
  285. unsigned long  writtenNumSize _AP((data_tag tag,long num));
  286.  
  287. void doList _AP((void** list,void (*func)()));
  288.  
  289. char* writeProtocolVersion _AP((char* buf,long* len));
  290. char* defaultImplementationID _AP((void));
  291. char* defaultImplementationName _AP((void));
  292. char* defaultImplementationVersion _AP((void));
  293.  
  294. #ifdef __cplusplus
  295.     }
  296. #endif /* def __cplusplus */
  297.  
  298. /*----------------------------------------------------------------------*/
  299.  
  300. #endif /* ndef _H_utils_Z39_50 */
  301.